//
//  SettingVC.swift
//  YueChat
//
//  Created by IMac on 2024/9/13.
//

import UIKit

class SettingVC: BaseVC {

    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        title = "设置"
        setup()
    }


    func setup () {
        dataSource = ["账号与安全","隐私设置"]
        
        tableView.dataSource = self
        tableView.delegate = self

        tableView.register(UINib(nibName: "LogoutCell", bundle: nil), forCellReuseIdentifier: "LogoutCell")
    }
    

  
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 60
    }
    
    func numberOfSections(in tableView: UITableView) -> Int {
        return 2
    }
    
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        if section == 0 {
            return dataSource.count
        }
        return 1
    }
    
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 0.001
    }
    
//    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
//        let view = UIView(frame: CGRect(x: 0, y: 0, width: kScreenWidth, height: 10))
//        view.backgroundColor = UIColor.lightGray
//        return view
//    }
    
    func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return 10
    }
    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
            
        if indexPath.section == 0 {
            let cell = UITableViewCell(style: .default, reuseIdentifier: "cell")
            cell.contentView.backgroundColor = UIColor.clear
            cell.accessoryType = .disclosureIndicator
            let str = dataSource[indexPath.row] as? String
            cell.textLabel?.text = str
            return cell
        }
        let cell = tableView.dequeueReusableCell(withIdentifier: "LogoutCell", for: indexPath) as! LogoutCell
        cell.titleLab.text = "退出登录"
        return cell
    }
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

        tableView.deselectRow(at: indexPath, animated: true)
        
        if indexPath.section == 1 {
            MHAlert.showCustomAlert(KLocalizedString("AlertQuiteLogin")) { ac in
                if ac.title == KLocalizedString("Sure") {
                    MHAlert.showMessage(KLocalizedString("AlertLoginOutSuccess"))
                    InfoManager.shared.loginOut()
                }
            }
        }else{
            if indexPath.row == 0 {
                navigationController?.pushViewController(AccountManagerVC(), animated: true)
            }else if indexPath.row == 1 {
                navigationController?.pushViewController(PrivacySetVC(), animated: true)
            }
        }
        

        
    }

}
